package com.example.mybubbleshooter;




import android.os.Bundle;
import android.provider.Contacts.Intents.UI;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Typeface;
import android.util.DisplayMetrics;
import android.view.Display;
import android.view.Menu;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.view.View.OnClickListener;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends Activity implements OnClickListener{
	
	public static final String PREFS_NAME = "sampleGameSettings";		
	public static Typeface tf;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

			 setContentView(R.layout.main);
         
	        tf = Typeface.createFromAsset(getAssets(),"data/fonts/floral.ttf");
	        
	        TextView tv = (TextView) findViewById(R.id.start);
	        TextView tv1 = (TextView) findViewById(R.id.quick);
	        TextView tv2 = (TextView) findViewById(R.id.settings);
	        TextView tv3 = (TextView) findViewById(R.id.about);
	        TextView tv4 = (TextView) findViewById(R.id.exit);
	        
	        tv.setTypeface(tf);
	        tv1.setTypeface(tf);
	        tv2.setTypeface(tf);
	        tv3.setTypeface(tf);
	        tv4.setTypeface(tf);
	        
	        tv.setOnTouchListener(new CustomTouchListener());
	        tv1.setOnTouchListener(new CustomTouchListener());
	        tv2.setOnTouchListener(new CustomTouchListener());
	        tv3.setOnTouchListener(new CustomTouchListener());
	        tv4.setOnTouchListener(new CustomTouchListener());
	        
	        tv.setOnClickListener(this);
	        tv1.setOnClickListener(this);
	        tv2.setOnClickListener(this);
	        tv3.setOnClickListener(this);
	        tv4.setOnClickListener(this);        
	        
	        Toast.makeText(this, "Press Menu to Start Game", Toast.LENGTH_LONG).show();
		
		getSettings();
		setDate();
		
		

	}
	


	private boolean[] settingsHolder = new boolean[5];

	private void getSettings() {
		SharedPreferences settings = getSharedPreferences(
				MainActivity.PREFS_NAME, 0);

		settingsHolder[0] = settings.getBoolean("sound", true);
		settingsHolder[1] = settings.getBoolean("music", true);
		settingsHolder[2] = settings.getBoolean("vibrate", true);
		settingsHolder[3] = settings.getBoolean("level1", true);
		settingsHolder[4] = settings.getBoolean("level2", true);

	}
	
	private void setDate(){
		Global.soundEnabled=settingsHolder[0];
		Global.vibertaeEnabled=settingsHolder[2];
		if(!settingsHolder[3]&&!settingsHolder[4])
			Global.currentLevel=Global.EASY;
		else if(settingsHolder[3]&&!settingsHolder[4])
			Global.currentLevel=Global.MEDIUM;
		else
			Global.currentLevel=Global.HARD;
			
		}
	
	
	@Override
	protected void onDestroy() {
		// TODO Auto-generated method stub
		super.onDestroy();
	
	}
//	public void startGame(){
//		init();
//		Global.initGlobal();
//		Map.generateMap();
//		// requesting to turn the title OFF
////        requestWindowFeature(Window.FEATURE_NO_TITLE);
////        // making it full screen
////        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
//        // set our MainGamePanel as the View
//		
//		drawView = new PlayView(this);
////		LayoutInflater inflater = LayoutInflater.from(this);
//////		setContentView(R.layout.main);
//////		mainview = (LinearLayout) this.findViewById(R.id.main);
////		playerview = (LinearLayout) inflater.inflate(R.layout.player, null);
////		
//		
//		
//	//	Activity v=getParent();
////		ViewGroup vg = (ViewGroup)(getParent());
////		vg.removeView(myView);
//		setContentView(0);
//		setContentView(drawView);
//	}
	


	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

	
	@Override
	public void onClick(View v) {
		
		switch(v.getId()){
			case R.id.start:
//			startGame();
				Intent j = new Intent(this, DrawActivity.class);
				startActivity(j);
				break;
			
			case R.id.quick:
				
				break;
			case R.id.settings:
				Intent i = new Intent(this, SettingsActivity.class);
				startActivity(i);
				break;
			case R.id.about:
				makeDialog();
				break;	
			case R.id.exit:
				finish();
				//System.exit(0);
				break;
		}
		
	}
	
	private void makeDialog() {		
		
	    AlertDialog.Builder dialog = new AlertDialog.Builder(this);	    
	    
	    dialog.setMessage("This is a demo");

	    dialog.setPositiveButton("Buy the full version", new DialogInterface.OnClickListener() {
	        public void onClick(DialogInterface arg0, int arg1) {
	        	Toast.makeText(getBaseContext(), "BUY IT", Toast.LENGTH_LONG).show();
	        }
	    });
	
	    dialog.setNegativeButton("Close", new DialogInterface.OnClickListener() {
	        public void onClick(DialogInterface arg0, int arg1) {}
	    });
	
	    dialog.show();
	}
}
